//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.ruoyi.live.user.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.live.app.service.CacheService;
import com.ruoyi.live.configuration.SessionInfo;
import com.ruoyi.live.configuration.SessionName;
import com.ruoyi.live.base.domain.*;
import com.ruoyi.live.base.mapper.*;
import com.ruoyi.live.base.domain.vo.TaskParam;
import com.ruoyi.live.base.service.IUserService;
import com.ruoyi.live.tool.commons.ICommons;
import com.ruoyi.live.tool.commons.IConvert;
import com.ruoyi.live.tool.commons.IMD5;
import com.ruoyi.live.tool.utils.PageTotalResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Map.Entry;
import java.util.stream.Collectors;

@Service
public class TeacherService {
    @Autowired
    CacheService cacheService;
    @Autowired
    LiveBarrageChannelMapper bcDao;
    @Autowired
    LiveTaskUserChannelMapper channelDao;
    @Autowired
    SystemClassMapper classDao;
    @Autowired
    UserMapper userDao;
    @Autowired
    TaskMapper taskDao;
    @Autowired
    IUserService userService;
    @Autowired
    TaskCatalogMapper catalogDao;
    @Autowired
    TaskUserLearnLogMapper logDao;
    @Autowired
    JdbcTemplate jdbcTemplate;
    @Autowired
    TaskUserRecordMapper recordDao;

    public TeacherService() {
    }

    public List<LiveBarrage> getBarrageList(Long id, Integer index) {
        List<LiveBarrage> res = new ArrayList();
        List<LiveBarrageChannel> bcs = this.bcDao.selectList(new QueryWrapper((new LiveBarrageChannel()).setChannelId(id).setTimeIndex(index)));
        Iterator var5 = bcs.iterator();

        while(var5.hasNext()) {
            LiveBarrageChannel bc = (LiveBarrageChannel)var5.next();
            LiveBarrage lb = this.cacheService.getOneBarrage(bc.getBarrageId());
            lb.setAddCount(bc.getUserAddCount());
            lb.setUserName(bc.getFromUserName());
            lb.setLevel(bc.getFromUserLevel());
            res.add(lb);
        }

        return res;
    }

    public LiveTaskUserChannel getChannel() {
        return (LiveTaskUserChannel)this.channelDao.selectById(136L);
    }

    public List<User> query(User entity) {
        return null;
    }

    public List<SystemClass> queryClass(SystemClass entity) {
        return this.classDao.selectList(new QueryWrapper((new SystemClass()).setTeacherId(SessionInfo.getUserId())));
    }

    public List<TaskCatalog> getTaskList(Task entity) {
        Long classId = SessionInfo.getClassId();
        Long studentCount = this.userDao.selectCount(new QueryWrapper((new User()).setClassId(classId).setUserType(3)));
        List<Task> tasks = this.taskDao.selectTaskCount(classId, studentCount.intValue(), entity.getTaskName(), entity.getCatalogId());
        List<TaskCatalog> list = null;
        if (!ICommons.isNullOrEmpty(entity.getCatalogId())) {
            list = new ArrayList();
            ((List)list).add(this.catalogDao.selectById(entity.getCatalogId()));
        } else {
            list = this.catalogDao.selectList((Wrapper)(new QueryWrapper(new TaskCatalog())).orderByAsc("orders"));
        }

        Map<Long, TaskCatalog> map = (Map)((List)list).stream().collect(Collectors.toMap(TaskCatalog::getId, (cata) -> {
            return cata;
        }));

        Iterator var7;
        Task task;
        for(var7 = tasks.iterator(); var7.hasNext(); ((TaskCatalog)map.get(task.getCatalogId())).getTasks().add(task)) {
            task = (Task)var7.next();
            List<Task> ts = ((TaskCatalog)map.get(task.getCatalogId())).getTasks();
            if (ts == null) {
                ((TaskCatalog)map.get(task.getCatalogId())).setTasks(new ArrayList());
            }
        }

        var7 = ((List)list).iterator();

        while(var7.hasNext()) {
            TaskCatalog catalog = (TaskCatalog)var7.next();
            catalog.setCount(catalog.getTasks().size());
        }

        return (List)list;
    }

    public List<SystemClass> queryAllClass() {
        return SessionInfo.getUser().getUserType() == 1 ? this.classDao.selectList((Wrapper)null) : this.classDao.selectList(new QueryWrapper((new SystemClass()).setTeacherId(SessionInfo.getUserId())));
    }

    public Map<String, Integer> getIndexDatas() {
        Map<String, Integer> datas = new HashMap();
        datas.put("studentCount", this.userDao.selectCount(new QueryWrapper((new User()).setClassId(SessionInfo.getClassId()))).intValue());
        datas.put("taskCount", this.taskDao.selectCount(new QueryWrapper((Object)null)).intValue());
        datas.put("taskComplete", this.logDao.selectCount(new QueryWrapper((new TaskUserLearnLog()).setClassId(SessionInfo.getClassId()).setState(2))).intValue());
        datas.put("taskToScore", this.logDao.selectCount(new QueryWrapper((new TaskUserLearnLog()).setState(2).setScoreState(1).setClassId(SessionInfo.getClassId()))).intValue());
        return datas;
    }

    public Map<String, Object> getBarDatas() {
        Long classId = SessionInfo.getClassId();
        String sql = "select aa.*,bb.user_login_name name from (select count(1) count,create_user from task_user_learn_log a where a.state = 2 and a.class_id = " + classId + " group by create_user  order by  count desc limit 10) aa left join user bb on aa.create_user = bb.id";
        List<Map<String, Object>> res = this.jdbcTemplate.queryForList(sql);
        List<String> x = new ArrayList();
        List<Integer> y = new ArrayList();
        Iterator var6 = res.iterator();

        while(var6.hasNext()) {
            Map<String, Object> map = (Map)var6.next();
            x.add(IConvert.object2string(map.get("name")));
            y.add(IConvert.object2int(map.get("count")));
        }

        Map<String, Object> result = new HashMap();
        result.put("x", x);
        result.put("y", y);
        result.put("all", this.taskDao.selectCount(new QueryWrapper((Object)null)));
        return result;
    }

    public List<Map<String, Object>> getTodos() {
        Long classId = SessionInfo.getClassId();
        String sql = "select d.catalog_name,a.create_time,a.id,a.catalog_id,a.task_id,c.task_name,IFNULL(b.user_real_name,b.user_login_name) name from (select * from task_user_learn_log where state = 2 and score_state = 1  and class_id = " + classId + ") a left join user b on a.create_user = b.id left join task c on a.task_id = c.id  left join task_catalog d on a.catalog_id = d.id order by a.create_time limit 5";
        return this.jdbcTemplate.queryForList(sql);
    }

    public List<Map<String, Object>> getMaxs() {
        Long classId = SessionInfo.getClassId();
        String sql = "select aaa.*,bbb.user_login_name name from (select aa.*,(@ranknum:=@ranknum+1) as rank from (select round(max(score),2) score,create_user from task_user_learn_log a where a.state = 2 and a.score_state = 2 and a.class_id = " + classId + " group by create_user  order by  score desc)aa,(select (@ranknum :=0) ) b limit 5) aaa left join user bbb on aaa.create_user = bbb.id";
        return this.jdbcTemplate.queryForList(sql);
    }

    public List<Map<String, Object>> getAvgs() {
        Long classId = SessionInfo.getClassId();
        String sql = "select aaa.*,bbb.user_login_name name from (select aa.*,(@ranknum:=@ranknum+1) as rank from (select round(avg(score),2) score,create_user from task_user_learn_log a where a.state = 2 and a.score_state = 2 and a.class_id = " + classId + "  group by create_user  order by  score desc)aa,(select (@ranknum :=0) ) b limit 5) aaa left join user bbb on aaa.create_user = bbb.id";
        return this.jdbcTemplate.queryForList(sql);
    }

    public Map<String, Object> scatter() {
        Long classId = SessionInfo.getClassId();
        String sql = "select a.*,IFNULL(b.user_real_name,b.user_login_name) name from (select count(1) count,round(avg(score),2) avg,round(max(score),2) max,create_user  from task_user_learn_log where class_id = " + classId + " and state = 2 and score_state = 2 group by create_user)a  left join user b on a.create_user = b.id";
        List<Map<String, Object>> list = this.jdbcTemplate.queryForList(sql);
        List<List<Object>> avgs = new ArrayList();
        List<List<Object>> maxs = new ArrayList();
        List<String> names = new ArrayList();
        Iterator var7 = list.iterator();

        while(var7.hasNext()) {
            Map<String, Object> map = (Map)var7.next();
            List<Object> avg = new ArrayList();
            List<Object> max = new ArrayList();
            avg.add(map.get("count"));
            avg.add(map.get("avg"));
            avgs.add(avg);
            max.add(map.get("count"));
            max.add(map.get("max"));
            maxs.add(max);
            names.add(IConvert.object2string(map.get("name")));
        }

        Map<String, Object> result = new HashMap();
        result.put("avgs", avgs);
        result.put("maxs", maxs);
        result.put("names", names);
        result.put("counts", this.taskDao.selectCount(new QueryWrapper((Object)null)));
        return result;
    }

    public Integer getCountByDate(Long start, Long end) {
        Long classId = SessionInfo.getClassId();
        String sql = "select count(1) count from task_user_record where class_id = " + classId + " and create_time >= ? and create_time <= ?";
        return (Integer)this.jdbcTemplate.queryForObject(sql, Integer.class, new Object[]{start, end});
    }

    public Map<String, Object> getDatas() {
        Long classId = SessionInfo.getClassId();
        Calendar calendar = Calendar.getInstance();
        Long now = calendar.getTimeInMillis();
        calendar.set(6, calendar.get(6) - 1);
        Long before1 = calendar.getTimeInMillis();
        calendar.set(6, Calendar.getInstance().get(6) - 2);
        Long before2 = calendar.getTimeInMillis();
        calendar.set(6, Calendar.getInstance().get(6) - 7);
        Long before7 = calendar.getTimeInMillis();
        calendar.set(6, Calendar.getInstance().get(6) - 14);
        Long before14 = calendar.getTimeInMillis();
        calendar.set(6, Calendar.getInstance().get(6) - 30);
        Long before30 = calendar.getTimeInMillis();
        calendar.set(6, Calendar.getInstance().get(6) - 60);
        Long before60 = calendar.getTimeInMillis();
        Map<String, Object> res = new HashMap();
        res.put("now", this.recordDao.selectCount(new QueryWrapper((new TaskUserRecord()).setClassId(classId))));
        int day1 = this.getCountByDate(before1, now);
        res.put("day1", day1);
        int day2 = this.getCountByDate(before2, before1);
        DecimalFormat df = new DecimalFormat("#.0");
        if (day1 != 0 && day2 != 0) {
            double day_percent = (double)(day1 - day2) / (double)day2 * 100.0D;
            res.put("day_percent_has", true);
            res.put("day_percent_up", day_percent > 0.0D);
            res.put("day_percent", df.format(day_percent * (double)(day_percent > 0.0D ? 1 : -1)));
        } else {
            res.put("day_percent_has", false);
        }

        int day7 = this.getCountByDate(before7, now);
        res.put("day7", day7);
        int day14 = this.getCountByDate(before14, before7);
        if (day7 != 0 && day14 != 0) {
            double week_percent = (double)(day7 - day14) / (double)day14 * 100.0D;
            res.put("week_percent_has", true);
            res.put("week_percent_up", week_percent > 0.0D);
            res.put("week_percent", df.format(week_percent * (double)(week_percent > 0.0D ? 1 : -1)));
        } else {
            res.put("week_percent_has", false);
        }

        int day30 = this.getCountByDate(before30, now);
        res.put("day30", day30);
        int day60 = this.getCountByDate(before60, before30);
        if (day60 != 0 && day30 != 0) {
            double month_percent = (double)(day30 - day60) / (double)day60 * 100.0D;
            res.put("month_percent_has", true);
            res.put("month_percent_up", month_percent > 0.0D);
            res.put("month_percent", df.format(month_percent * (double)(month_percent > 0.0D ? 1 : -1)));
        } else {
            res.put("month_percent_has", false);
        }

        return res;
    }

    public Map<String, Object> line(TaskUserRecord record) {
        Long classId = SessionInfo.getClassId();
        String params = "";
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        if (!ICommons.isNullOrEmpty(record.getIds())) {
            params = params + " and type in (" + record.getIds() + ") ";
        }

        if (record.getCreateUser() != null) {
            params = params + " and create_user = " + record.getCreateUser() + " ";
        }

        try {
            if (!ICommons.isNullOrEmpty(record.getBegin())) {
                params = params + " and create_time >= " + format.parse(record.getBegin()).getTime() + " ";
            }

            if (!ICommons.isNullOrEmpty(record.getEnd())) {
                params = params + " and create_time <= " + format.parse(record.getEnd()).getTime() + " ";
            }
        } catch (Exception var14) {
            var14.printStackTrace();
        }

        String sqlLine = "select aa.* from (select count(1) count,create_time_cn tc from task_user_record  where class_id = " + classId + params + "  group by create_time_cn ) aa order by aa.tc";
        String sqlCount = "select count(1) count,type from task_user_record where class_id = " + classId + params + " group by type order by type";
        String sqlColumn = "select a.*,ifnull(b.user_real_name,b.user_login_name) name from (select count(1) count,create_user from task_user_record where class_id = " + classId + params + " group by create_user order by count desc limit 10) a left join user b on a.create_user = b.id";
        String sqlPie = "select a.count value,a.catalog_id,b.catalog_name name from (select count(1) count,catalog_id from task_user_record where class_id = " + classId + params + " group by catalog_id )a left join task_catalog b on a.catalog_id = b.id";
        List<Map<String, Object>> lineDatas = this.jdbcTemplate.queryForList(sqlLine);
        List<Map<String, Object>> countDatas = this.jdbcTemplate.queryForList(sqlCount);
        List<Map<String, Object>> columnDatas = this.jdbcTemplate.queryForList(sqlColumn);
        List<Map<String, Object>> pieDatas = this.jdbcTemplate.queryForList(sqlPie);
        Map<String, Object> res = new HashMap();
        res.put("lineDatas", lineDatas);
        res.put("countDatas", countDatas);
        res.put("columnDatas", columnDatas);
        res.put("pieDatas", pieDatas);
        return res;
    }

    public PageTotalResult listDatas(TaskUserRecord record) {
        String params = "";
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        List<Object> objs = new ArrayList();
        objs.add(SessionInfo.getClassId());
        if (!ICommons.isNullOrEmpty(record.getIds())) {
            params = params + " and type in (?) ";
            objs.add(record.getIds());
        }

        if (record.getCreateUser() != null) {
            params = params + " and create_user = ? ";
            objs.add(record.getCreateUser());
        }

        try {
            if (!ICommons.isNullOrEmpty(record.getBegin())) {
                params = params + " and create_time >= ? ";
                objs.add(format.parse(record.getBegin()).getTime());
            }

            if (!ICommons.isNullOrEmpty(record.getEnd())) {
                params = params + " and create_time <= ? ";
                objs.add(format.parse(record.getEnd()).getTime());
            }
        } catch (Exception var9) {
            var9.printStackTrace();
        }

        String sql = "select count(1) count from task_user_record where class_id=? " + params;
        Integer total = 0;
        List<Map<String, Object>> totals = this.jdbcTemplate.queryForList(sql, objs.toArray());
        if (totals.size() > 0) {
            total = IConvert.object2int(((Map)totals.get(0)).get("count"));
        }

        if (ICommons.isNullOrEmpty(record.getPageNum())) {
            record.setPageNum(1);
        }

        if (ICommons.isNullOrEmpty(record.getPageSize())) {
            record.setPageSize(10);
        }

        objs.add((record.getPageNum() - 1) * record.getPageSize());
        objs.add(record.getPageSize());
        sql = "select a.*,b.task_name,c.catalog_name,ifnull(d.user_real_name, d.user_login_name) user_name from (select * from task_user_record where class_id=? " + params + " order by create_time desc limit ?,?) a left join task b on a.task_id = b.id left join task_catalog c on a.catalog_id = c.id LEFT JOIN user d on a.create_user = d.id ";
        List<Map<String, Object>> records = this.jdbcTemplate.queryForList(sql, objs.toArray());
        return new PageTotalResult(records, total);
    }

    public List<TaskCatalog> getTasksFx(TaskParam param) {
        Long classId = SessionInfo.getClassId();
        List<TaskCatalog> list = this.cacheService.getTasks();
        Long stuCount = this.userDao.selectCount(new QueryWrapper((new User()).setUserType(3).setClassId(classId)));
        List<Map<String, Object>> maps = this.jdbcTemplate.queryForList("select count(1) do_count,round(count(1)/" + stuCount + "*100,2) count,task_id id from task_user_learn_log where state = 2 and class_id = " + classId + " group by task_id ");
        List<Map<String, Object>> dataMaps = this.jdbcTemplate.queryForList("select round(avg(score),2) score,mst.task_id id from task_user_learn_log mst where mst.score_state = 2 and mst.class_id = " + classId + " group by mst.task_id");
        Map<Long, Map<String, Object>> res = (Map)maps.stream().collect(Collectors.toMap((m) -> {
            return IConvert.object2long(m.get("id"));
        }, (m) -> {
            return m;
        }));
        Map<Long, Map<String, Object>> resDataMap = (Map)dataMaps.stream().collect(Collectors.toMap((m) -> {
            return IConvert.object2long(m.get("id"));
        }, (m) -> {
            return m;
        }));
        Map avgCountMap;
        if (param == null || ICommons.isNullOrEmpty(param.getPlatformId()) && ICommons.isNullOrEmpty(param.getTaskName())) {
            Iterator var17 = ((List)list).iterator();

            while(var17.hasNext()) {
                TaskCatalog cata = (TaskCatalog)var17.next();
                Iterator var19 = cata.getTasks().iterator();

                while(var19.hasNext()) {
                    Task task = (Task)var19.next();
                    task.setAllCount(stuCount.intValue());
                    Map<String, Object> taskCountMap = (Map)res.get(task.getId());
                    if (taskCountMap != null) {
                        task.setCount(IConvert.object2double(taskCountMap.get("count")));
                        task.setDoCount(IConvert.object2int(taskCountMap.get("do_count")));
                    } else {
                        task.setCount(0.0D);
                        task.setDoCount(0);
                    }

                    avgCountMap = (Map)resDataMap.get(task.getId());
                    if (avgCountMap != null) {
                        task.setAvg(IConvert.object2double(avgCountMap.get("score")));
                    } else {
                        task.setAvg(0.0D);
                    }
                }
            }
        } else {
            if (param.getTaskName().contains(";")) {
                param.setTaskName(param.getTaskName().replaceAll(";", ""));
            }

            List<Task> tasks = this.taskDao.selectList(((QueryWrapper)(new QueryWrapper()).eq(!ICommons.isNullOrEmpty(param.getPlatformId()), "catalog_id", param.getPlatformId())).like(!ICommons.isNullOrEmpty(param.getTaskName()), "task_name", param.getTaskName()));
            List<TaskCatalog> catas = this.catalogDao.selectList((Wrapper)null);
            Map<Long, TaskCatalog> map = (Map)catas.stream().collect(Collectors.toMap(TaskCatalog::getId, (catax) -> {
                return catax;
            }));
            Iterator var12 = tasks.iterator();

            while(var12.hasNext()) {
                Task task = (Task)var12.next();
                task.setAllCount(stuCount.intValue());
                avgCountMap = (Map)res.get(task.getId());
                if (avgCountMap != null) {
                    task.setCount(IConvert.object2double(avgCountMap.get("count")));
                    task.setDoCount(IConvert.object2int(avgCountMap.get("do_count")));
                } else {
                    task.setCount(0.0D);
                    task.setDoCount(0);
                }

                avgCountMap = (Map)resDataMap.get(task.getId());
                if (avgCountMap != null) {
                    task.setAvg(IConvert.object2double(avgCountMap.get("score")));
                } else {
                    task.setAvg(0.0D);
                }

                List<Task> ts = ((TaskCatalog)map.get(task.getCatalogId())).getTasks();
                if (ts == null) {
                    ts = new ArrayList();
                    ts.add(task);
                    ((TaskCatalog)map.get(task.getCatalogId())).setTasks(ts);
                } else {
                    ts.add(task);
                }
            }

            list = new ArrayList();
            var12 = map.entrySet().iterator();

            while(var12.hasNext()) {
                Entry<Long, TaskCatalog> entry = (Entry)var12.next();
                TaskCatalog mt = (TaskCatalog)entry.getValue();
                if (mt.getTasks() != null) {
                    mt.setCount(mt.getTasks().size());
                    ((List)list).add(mt);
                }
            }
        }

        return (List)list;
    }

    public Map<String, Object> getTasksFxDetail(Long id) {
        String sql = "select round(avg(score),2) avg,round(max(score),2) max,round(min(score),2) min from task_user_learn_log where class_id = " + SessionInfo.getClassId() + " and score_state = 2 and task_id = ?";
        List<Map<String, Object>> list = this.jdbcTemplate.queryForList(sql, new Object[]{id});
        if (list.size() > 0) {
            return (Map)list.get(0);
        } else {
            Map<String, Object> res = new HashMap();
            res.put("avg", 0);
            res.put("max", 0);
            res.put("min", 0);
            return res;
        }
    }

    public List<Task> fxListStudentTask(Task entity) {
        return this.taskDao.selectUserTask(SessionInfo.getClassId(), entity.getId());
    }

    public List<Task> fxColumnStudentTask(Task entity) {
        return this.taskDao.selectScores(SessionInfo.getClassId(), entity.getTaskName());
    }

    public Map<String, Object> getUserDetail(Long id, Integer count, Integer allCount) {
        Long classId = SessionInfo.getClassId();
        Map<String, Object> res = new HashMap();
        String sql = "select aaa.rank rank from (select @rownum := @rownum + 1 AS rank,aa.id from (select a.id,ifnull(b.count,0) count from user a left join (select count(1) count,create_user from task_user_learn_log where state = 2 and class_id=" + classId + " group by create_user ) b on a.id = b.create_user where a.user_type = 3 and a.class_id=" + classId + " order by b.count desc )aa,(SELECT @rownum := 0) r  )aaa where aaa.id=?";
        res.put("countrank", this.jdbcTemplate.queryForObject(sql, Integer.class, new Object[]{id}));
        sql = "select aaa.rank rank from (select @rownum := @rownum + 1 AS rank,aa.id from (select a.id,ifnull(b.count,0) count,round(ifnull(b.score,0),2) score from user a left join (select count(1) count,avg(score) score,create_user from task_user_learn_log where state = 2 and class_id=" + classId + " group by create_user ) b on a.id = b.create_user where a.user_type = 3 and a.class_id=" + classId + " order by b.score desc )aa,(SELECT @rownum := 0) r  )aaa where aaa.id=?";
        res.put("scorerank", this.jdbcTemplate.queryForObject(sql, Integer.class, new Object[]{id}));
        Double percent = (double)count * 100.0D / (double)allCount;
        res.put("percent", String.format("%.2f", percent));
        return res;
    }

    public List<TaskCatalog> getUserDetailList(Long id) {
        Long classId = SessionInfo.getClassId();
        List<TaskCatalog> list = this.cacheService.getTasks();
        List<Map<String, Object>> tasks = this.jdbcTemplate.queryForList("select max(c.state) state,max(c.score_state) score_state,c.task_id from task_user_learn_log c where c.create_user = ? and c.class_id = " + classId + " group by task_id", new Object[]{id});
        Map<Long, Map<String, Object>> res = (Map)tasks.stream().collect(Collectors.toMap((m) -> {
            return IConvert.object2long(m.get("task_id"));
        }, (m) -> {
            return m;
        }));
        Iterator var6 = list.iterator();

        while(var6.hasNext()) {
            TaskCatalog catalog = (TaskCatalog)var6.next();
            Iterator var8 = catalog.getTasks().iterator();

            while(var8.hasNext()) {
                Task mt = (Task)var8.next();

                try {
                    Map<String, Object> cen = (Map)res.get(mt.getId());
                    String stateName = "<span style='color:#808695'>未开始</span>";
                    if (cen != null) {
                        int state = IConvert.object2int(cen.get("state"));
                        int scoreState = IConvert.object2int(cen.get("score_state"));
                        if (state == 1) {
                            stateName = "<span style='color:#19be6b'>进行中</span>";
                        } else if (state == 2 && scoreState == 1) {
                            stateName = "<span style='color:#ff9900'>未批阅</span>";
                        } else if (state == 2 && scoreState == 2) {
                            stateName = "<span style='color:#2d8cf0'>已批阅</span>";
                        }
                    }

                    mt.setStateName(stateName);
                } catch (Exception var14) {
                    var14.printStackTrace();
                    mt.setState(0);
                    mt.setScoreState(0);
                }
            }
        }

        return list;
    }

    public List<SystemClass> getClses() {
        return this.classDao.selectList(new QueryWrapper((new SystemClass()).setTeacherId(SessionInfo.getUserId())));
    }

    public void addStudents(Integer count, String firstName, Long classId) throws Exception {
        Long has = this.userDao.selectCount((Wrapper)(new QueryWrapper(new User())).like("user_login_name", firstName));
        if (has != 0l) {
            throw new Exception("学生用户名开始字符已使用!");
        } else {
            List<User> list = new ArrayList();

            for(int i = 1; i <= count; ++i) {
                list.add((new User()).setUserLoginName(firstName + i).setUserLoginNameMd5(IMD5.getMD5(firstName + i)).setUserPasswordMd5(IMD5.getMD5("123456")).setUserCreateUserId(SessionInfo.getUserId()).setUserCreateTime(System.currentTimeMillis()).setClassId(classId).setUserSex(3).setUserType(3).setUserState(1));
            }

            this.userService.saveBatch(list);
        }
    }

    public void changeClass(Long id) {
        SystemClass sc = (SystemClass)this.classDao.selectById(id);
        SessionInfo.set(SessionName.Cls, sc);
        SessionInfo.set(SessionName.ClassId, sc.getId());
    }
}
